import Vue from 'vue'
import Router from 'vue-router'
import errorPage from '@/components/errorpage';
import { indexRoutes } from '@/components/index/router/index.routes'
import { userRoutes } from '@/components/user/router/user.routes'
import { carrRoutes } from '@/components/carrier/router/carrier.routes'
import { driverRoutes } from '@/components/driver/router/driver.routes'
import { scanBundleRoutes } from '@/components/scanBundle/router/scanBundle.routes'

import store from '../store'

Vue.use(Router)

import Axios from 'axios'
let userinfo = localStorage.userinfo ? JSON.parse(localStorage.userinfo) : null;

const router = new Router({
    routes: [
        //路径重定向
        { path: '/', redirect: '/login' },
        ...indexRoutes,
        ...userRoutes,
        ...driverRoutes,
        ...carrRoutes,
        ...scanBundleRoutes,
        //默认错误地址跳转页
        {
            path: '*',
            name: 'errorPage',
            component: errorPage
        }
    ]
})

//路由权限跳转控制
router.beforeEach((to, from, next) => {
    //抓取访问记录
    // if (userinfo == null) {
    //   userinfo = {
    //     Name: '未登录',
    //     LogonUser: '',
    //   }
    // }
    // let log = `登录用户：${userinfo.Name}；账号：${userinfo.LogonUser}；访问页面：${to.name}，路径：${location.protocol}//${location.host}${to.path}`,
    //     JLog = {
    //         UserName: userinfo.Name,
    //         LogonUser: userinfo.LogonUser,
    //         PageName: to.name,
    //         Path: `${location.protocol}//${location.host}${to.path}`,
    //         Content: log,
    //     };
    // Axios.post(`${process.env.API_ROOT}/api/webchart/AccessRecording`, JLog);
    //抓取访问记录

    next();
})

export default router